import 'package:flutter/material.dart';
import '../models/user_model.dart';

class ProfileForm extends StatelessWidget {
  final GlobalKey<FormState> formKey;
  final User user;

  const ProfileForm({
    super.key,
    required this.formKey,
    required this.user,
  });

  @override
  Widget build(BuildContext context) {
    return Form(
      key: formKey,
      child: Column(
        children: [
          TextFormField(
            decoration: const InputDecoration(
              labelText: 'Full Name',
              prefixIcon: Icon(Icons.person),
            ),
            validator: (value){
              if(value == null|| value.isEmpty){
                return 'Plz enter ur name';
              }
              return null;
            },
            onSaved: (value)=>user.name = value!,
          ),
          const SizedBox(height: 15),
          TextFormField(
            decoration: const InputDecoration(
              labelText: 'Email',
              prefixIcon: Icon(Icons.email),
            ),
            validator: (value){
              if(value ==null||value.isEmpty){
                return 'Plz enter ur email';
              }
              return null;
            },
            onSaved: (value)=>user.email = value!,
          ),
          const SizedBox(height: 15),
          TextFormField(
            decoration: const InputDecoration(
              labelText: 'Phone',
              prefixIcon: Icon(Icons.phone),
            ),
            validator: (value){
              if(value==null||value.isEmpty){
                return  'Plz enter ur phone';
              }
              if(value.length<10){
                return  'Phone number too short';
              }
              return null;
            },
            onSaved: (value)=>user.phone = value!,
          ),
          const SizedBox(height: 15),
          TextFormField(
            decoration: const InputDecoration(
              labelText: 'Bio',
              prefixIcon: Icon(Icons.info),
            ),
            maxLines: 3,
            validator: (value){
              if(value==null||value.isEmpty){
                return  'Plz enter ur phone';
              }
            },
            onSaved: (value)=>user.bio = value!,
          )
        ],
      ),
    );
  }


}
